#ifndef _CCBONETRANSFORM_H_
#define _CCBONETRANSFORM_H__

#include "CCTransform.h"
#include "CCSkeletalSprite.h"
#include <vector>
#include <cmath>

using namespace std;

/**
 * transform of bone, it records key frames of one bone
 */



class CCBone;

class CCBoneTransform : public CCTransform {
public:			
	/// key frame of rotation
	struct RotationKeyFrame : public KeyFrame {
		/// angle in degree, positive value is counter-clockwise
		float angle;
	};
	
	/// key frame of translation
	struct TranslationKeyFrame : public KeyFrame {
		/// x offset
		float x;
		
		/// y offset
		float y;
	};
	
	/// key frame of scale
	struct ScaleKeyFrame : public KeyFrame {
		/// x scale
		float scaleX;
		
		/// y scale
		float scaleY;
	};
	
private:
	
	/// current rotation
	RotationKeyFrame m_currentRotation;
	
	/// current translation
	TranslationKeyFrame m_currentTranslation;
	
	/// current scale
	ScaleKeyFrame m_currentScale;
	
	/// key frame list of rotation
	typedef vector<RotationKeyFrame> RotationKeyFrameList;
	RotationKeyFrameList m_rkfList;
	
	/// key frame list of translation
	typedef vector<TranslationKeyFrame> TranslationKeyFrameList;
	TranslationKeyFrameList m_tkfList;
	
	/// key frame list of scale
	typedef vector<ScaleKeyFrame> ScaleKeyFrameList;
	ScaleKeyFrameList m_skfList;
    
    CCBone* _bone;
	
protected:
	CCBoneTransform();
    CCBoneTransform(CCBone* bone);
	
public:
	virtual ~CCBoneTransform();
	static CCBoneTransform* create(CCBone* bone);
	
	virtual void populateFrame(float time);
	
	virtual void applyTo(CCSkeletalSprite* owner,float alpha=1);

	/// add rotation key frame
	void addRotationKeyFrame(RotationKeyFrame kf);

	/// add translation key frame
	void addTranslationKeyFrame(TranslationKeyFrame kf);

	/// add scale key frame
	void addScaleKeyFrame(ScaleKeyFrame kf);
	
	/// get current rotation frame
	RotationKeyFrame& getRotationFrame() { return m_currentRotation; }
	
	/// get current translation frame
	TranslationKeyFrame& getTranslationFrame() { return m_currentTranslation; }
	
	/// get current scale frame
	ScaleKeyFrame& getScaleFrame() { return m_currentScale; }
};



#endif // __CCBoneTransform_h__
